<template>
    <div id="buynum">
        <div id="buyStyle">
            <div @click='subtract'>-</div>
            <div v-text="num">1</div>
            <div @click="add">+</div>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            num: 1
        }
    },
    methods: {
        add() {
            this.num++;
            this.sendmsg()
        },  
        subtract() {
            this.num--;
            if (this.num < 1) {
                this.num = 1;
            }
            this.sendmsg()
        },
        sendmsg() {
            this.$emit("dataobj", this.num)
        }
    }
}
</script>
<style scoped>
#buynum {
    position: relative;
    left: 0;
    top: 0;
}

#buyStyle {
    position: absolute;
    top: -35px;
    left: 90px;
}

#buyStyle div {
    display: inline-block;
    width: 50px;
    height: 28px;
    border: 1px solid black;
    text-align: center;
    line-height: 28px;
}
</style>


